<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>
<!DOCTYPE html>
<html>
  <head>
    <title></title>
  <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
    </style>
  </head>
  <body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
    	<h1>预约管理</h1>
		<ol class="breadcrumb">
			<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
			<li class="active">药品招标管理</li>
            <li class="active">预约管理</li>
		</ol>
		
	</section>
        <section class="content">
         <div class=" box box-success">
			<div class="box-body">
			 <div class=" form-inline">
			  <div class="">
			  <label style="vertical-align: middle;font-size: 25px;margin-left: 10px;">项目：</label>
			  <font size="3pt;"><c:out value="${projName }"></c:out></font>
			   <label style="vertical-align: middle;font-size: 25px;margin-left: 120px;">选择日期：</label>
			    <select id="subDate" class="form-control" style="margin-left: 20px;height: 35px;width: 200px;font-size: 16pt;" onchange="getDateAdd();">
                <c:forEach items="${listDate}" var="mapDate"  >
                    <option  style="width: 100%;height: 35px;font-size: 20pt;" id="${map.bidSubscribeDetailId }">${mapDate.subscribeDateStr}</option>
                  </c:forEach>
				</select> 
			<!-- 	
			 <div id="datepickertest1" style="width: 160px;" ></div>
			<div id="page_output" style="text-align:center; margin-top:80px; margin-bottom:20px; "></div> -->
			</div> 
			
			<br></br>
			<div class="form-group form-group-xs" id="TimeList">
			<c:if test="${listDate == '[]'}">
			 <font color="red" size="20pt;" style="margin-left: 330px;">预约活动已关闭</font>
			</c:if>
			    <c:forEach items="${listTime}" var="map">
			    <c:if test="${map.subCount == map.preSubCount && subOverlist.subscribeStarttime != map.subscribeStarttimeStr && subOverlist.subscribeDate == listDate[0].subscribeDateStr }">
			      <div class="external-event bg-red" style="width: 200px;height: 35px;float: left;margin-left: 10px;margin-top: 10px;" id="${map.bidSubscribeDetailId }" draggable="false" onclick="getTimeout('${map.bidSubscribeDetailId }','${map.subscribeStarttimeStr}','${map.subscribeEndtimeStr }');">${map.subscribeStarttimeStr} - ${map.subscribeEndtimeStr } 
                  	<div style="position: relative;margin: 0 0 10 200;text-align: right;">${map.subCount}/${map.preSubCount}</div>
                  </div>
			    </c:if>
			     <c:if test="${map.subCount == map.preSubCount && subOverlist.subscribeStarttime == map.subscribeStarttimeStr && subOverlist.subscribeDate == listDate[0].subscribeDateStr}">
			      <div class="external-event bg-yellow" style="width: 200px;height: 35px;float: left;margin-left: 10px;margin-top: 10px;" id="${map.bidSubscribeDetailId }" draggable="false" onclick="getTimeout('${map.bidSubscribeDetailId }','${map.subscribeStarttimeStr}','${map.subscribeEndtimeStr }');">${map.subscribeStarttimeStr} - ${map.subscribeEndtimeStr } 
                  	<div style="position: relative;margin: 0 0 10 200;text-align: right;">${map.subCount}/${map.preSubCount}</div>
                  </div>
			    </c:if>
			      <c:if test="${map.subCount != map.preSubCount && subOverlist.subscribeStarttime == map.subscribeStarttimeStr && subOverlist.subscribeDate == listDate[0].subscribeDateStr }">
			     <div class="external-event bg-yellow" style="width: 200px;height: 35px;float: left;margin-left: 10px;margin-top: 10px;" id="${map.bidSubscribeDetailId }" onclick="getTime('${map.bidSubscribeDetailId }','${map.subscribeStarttimeStr}','${map.subscribeEndtimeStr }');">${map.subscribeStarttimeStr} - ${map.subscribeEndtimeStr } 
                  	<div style="position: relative;margin: 0 0 10 200;text-align: right;">${map.subCount}/${map.preSubCount}</div>
                  </div>
			    </c:if>
			    <c:if test="${map.subCount != map.preSubCount && subOverlist.subscribeStarttime != map.subscribeStarttimeStr}">
			     <div class="external-event bg-green" style="width: 200px;height: 35px;float: left;margin-left: 10px;margin-top: 10px;" id="${map.bidSubscribeDetailId }" onclick="getTime('${map.bidSubscribeDetailId }','${map.subscribeStarttimeStr}','${map.subscribeEndtimeStr }');">${map.subscribeStarttimeStr} - ${map.subscribeEndtimeStr } 
                  	<div style="position: relative;margin: 0 0 10 200;text-align: right;">${map.subCount}/${map.preSubCount}</div>
                  </div>
			    </c:if>
                 
                </c:forEach>
                  <div class="box-footer text-center" style="margin-top: 320px;" >
                  <c:if test="${listDate != '[]'}">
                     <button type="button" onclick="save();" class="btn btn-success btn-sm">预&nbsp;约</button>
                    <c:if test="${defalutProjId == null}">
                    <button type="button" onclick="back();" class="btn btn-default btn-sm">返&nbsp;回</button>
                    </c:if>
                    <c:if test="${defalutProjId != null}">
                    <button type="button" onclick="look();" class="btn btn-default btn-sm">查&nbsp;看</button>
                    </c:if>
                  </c:if>
                  </div>
                  </div>
              </div>
              </div>
           </div>
               <form action="${ctx}/bidSubscribeRecord/toSuccessJsp.html" method="post" id="FormSuccess">
			<input type="hidden" id="bidSubscribeIdSuc" name="bidSubscribeId">
			<input type="hidden" id="subscribeDateSuc" name="subscribeDate">
			<input type="hidden" id="subscribeStarttime" name="subscribeStarttime">
			<input type="hidden" id="subscribeEndtime" name="subscribeEndtime">
			<input type="hidden" id="projNameSuc" name="projName" value="${projName }">
		</form>
        </section>
     
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    
    <script type="text/javascript">
    
   /*  $(function(){
    	var arr = "${listDate}";
    	if("[]" == arr || "" == "${listDate}"){
    		$.HN.message.alert("预约活动已关闭", '信息', 'warn');
    		return;
    	}
    	
    }); */
    
    var  strDate ="";
    var id = "";
    var startTime="";
    var endTime="";
	/* var include = "${list.includeWeekend}"
	if(include==0){
		$("#datepickertest1").datepicker({beforeShowDay: $.datepicker.noWeekends,minDate: new Date(2015, 10 - 2, 1), maxDate: "+3D" ,onSelect:function (a,inst){
			 var day1 = $("#datepickertest1").datepicker('getDate').getDate();                 
	         var month1 = $("#datepickertest1").datepicker('getDate').getMonth() + 1;             
	         var year1 = $("#datepickertest1").datepicker('getDate').getFullYear();
	         var fullDate = year1 + "-" + month1 + "-" + day1;
	 		  var str_output = "<h1>" + fullDate + "</h1><br/><br>";
	         page_output.innerHTML = str_output; 
	 		 strDate=fullDate;
		}});
	}
	if(include==1){
		$("#datepickertest1").datepicker({minDate: new Date(2015, 10 - 2, 1), maxDate: "+3D" ,onSelect:function (a,inst){
			 var day1 = $("#datepickertest1").datepicker('getDate').getDate();                 
	         var month1 = $("#datepickertest1").datepicker('getDate').getMonth() + 1;             
	         var year1 = $("#datepickertest1").datepicker('getDate').getFullYear();
	         var fullDate = year1 + "-" + month1 + "-" + day1;
	 		  var str_output = "<h1>" + fullDate + "</h1><br/><br>";
	          page_output.innerHTML = str_output; 
	 		 strDate=fullDate;
		}});
	} */
    
    
    function getTime(detailId,start,end){
  	  if(id != "" || id != detailId){
  		  $("#"+id+"").attr("class","external-event bg-green ui-draggable ui-draggable-handle");
  	  } 
  	  $("#"+detailId+"").attr("class","external-event bg-yellow ui-draggable ui-draggable-handle");
  	  id = detailId;
  	  startTime=start;
  	  endTime=end;
  }
    
      function save(){
    	  
    	  if(!validate()){
    		  return;
    	  }
    	 /*  var arr = new Array(); 
    	  arr = StrTime.split(" - ");
    	  var startTime = arr[0];
    	  var endTime = arr[1]; */
    	  $.HN.message.confirm('确定要预约吗？', '', '').on(function (e) {
              if (e) {
    	  $.ajax({
				type : "POST",
				url : "${ctx}/bidSubscribeDetail/saveBidSubscribeDetail.html?ts=" + Math.random(),
				data : {"subscribeDate" : strDate,
						"subscribeStarttime":startTime,
						"subscribeEndtime" : endTime,
						"bidSubscribeId":"${bidSubscribeId}"
						},
				dataType:"json",
				
				success : function(result) {
					if(result.success){
						$.alert('操作成功！','success');
						$("#subscribeDateSuc").val(strDate);
						$("#subscribeStarttime").val(startTime);
						$("#subscribeEndtime").val(endTime);
						$("#FormSuccess").submit();
					}else{
						$.alert(result.msg || '操作失败！','信息', 'error');
					}
				}
			});
              }
              });
      }
      
      function validate(){
    	   strDate = $("#subDate").val()
			if (strDate == null || strDate == "") {
				$.HN.message.alert("请选择预约的日期！", "消息", "warn");
				return false;
			} 
			
			
			if (id == null || id == "") {
				$.HN.message.alert("请选择预约的时间！", "消息", "warn");
				return false;
			} 
			return true;
		}
      
      
      function  back(){
    	  window.location.href="${ctx}/bidSubscribe/toProduceSubscribeJsp.html";
      }
      
      function look(){
    	  window.location.href="${ctx}/bidSubscribeRecord/toListSuccessJsp.html?bidSubscribeId=${bidSubscribeId}"; 
      }
      
       function getDateAdd(){
    	   str = $("#subDate").val();
	  $.ajax({
			type : "POST",
			url : "${ctx}/bidSubscribeDetail/changeTime.html",
			data : {"subscribeDate" : str,
					"bidSubscribeId":"${bidSubscribeId}"},
			dataType:"json",
			success : function(result) {
				if(true){
				 $("#TimeList").html("");
				 var htmlStr = "";
				 var htmlAllStr = "";
				 var defaultProjId = result[result.length-1].defaultProjId;
				 var subDate= "";
				 var starttime = "";
				 if(null != result[result.length-1].successDate){
					  subDate = result[result.length-1].successDate.subscribeDate;
					  starttime = result[result.length-1].successDate.subscribeStarttime;
				 }
			
				 for(var i = 0;i < result.length-1;i++){
					 if(result[i].subCount == result[i].preSubCount && result[i].subscribeStarttimeStr != starttime){
						 htmlStr="<div class=\"external-event bg-red\" style=\"width: 200px;height: 35px;float: left;margin-left: 10px;margin-top: 10px;\" id=\""+result[i].bidSubscribeDetailId+"\" draggable=\"false\" onclick=\"getTimeout('"+result[i].bidSubscribeDetailId+"','"+result[i].subscribeStarttimeStr+"','"+result[i].subscribeEndtimeStr+"');\">"+result[i].subscribeStarttimeStr+" - "+result[i].subscribeEndtimeStr 
							 							+"<div style=\"position: relative;margin: 0 0 10  200;text-align: right;\">"+result[i].subCount+"/"+result[i].preSubCount+"</div>"
					 }
					 if(result[i].subCount == result[i].preSubCount && result[i].subscribeStarttimeStr == starttime && result[i].subscribeDateStr == subDate){
						 htmlStr="<div class=\"external-event bg-yellow\" style=\"width: 200px;height: 35px;float: left;margin-left: 10px;margin-top: 10px;\" id=\""+result[i].bidSubscribeDetailId+"\" draggable=\"false\" onclick=\"getTimeout('"+result[i].bidSubscribeDetailId+"','"+result[i].subscribeStarttimeStr+"','"+result[i].subscribeEndtimeStr+"');\">"+result[i].subscribeStarttimeStr+" - "+result[i].subscribeEndtimeStr 
							 							+"<div style=\"position: relative;margin: 0 0 10  200;text-align: right;\">"+result[i].subCount+"/"+result[i].preSubCount+"</div>"
					 }
					 if(result[i].subCount != result[i].preSubCount && result[i].subscribeStarttimeStr == starttime && result[i].subscribeDateStr == subDate){
						 htmlStr="<div class=\"external-event bg-yellow\" style=\"width: 200px;height: 35px;float: left;margin-left: 10px;margin-top: 10px;\" id=\""+result[i].bidSubscribeDetailId+"\" draggable=\"false\" onclick=\"getTimeout('"+result[i].bidSubscribeDetailId+"','"+result[i].subscribeStarttimeStr+"','"+result[i].subscribeEndtimeStr+"');\">"+result[i].subscribeStarttimeStr+" - "+result[i].subscribeEndtimeStr 
							 							+"<div style=\"position: relative;margin: 0 0 10  200;text-align: right;\">"+result[i].subCount+"/"+result[i].preSubCount+"</div>"
					 }
					 if(result[i].subCount != result[i].preSubCount && result[i].subscribeStarttimeStr != starttime || result[i].subscribeDateStr != subDate){
						 htmlStr = "<div class=\"external-event bg-green\" style=\"width: 200px;height: 35px;float: left;margin-left: 10px;margin-top: 10px;\" id=\""+result[i].bidSubscribeDetailId+"\" draggable=\"false\" onclick=\"getTime('"+result[i].bidSubscribeDetailId+"','"+result[i].subscribeStarttimeStr+"','"+result[i].subscribeEndtimeStr+"');\">"+result[i].subscribeStarttimeStr+" - "+result[i].subscribeEndtimeStr 
							+"<div style=\"position: relative;margin: 0 0 10  200;text-align: right;\">"+result[i].subCount+"/"+result[i].preSubCount+"</div>"
					 }
					 if(result[i].subCount != result[i].preSubCount && result[i].subscribeStarttimeStr != starttime && result[i].subscribeDateStr != subDate){
						 htmlStr = "<div class=\"external-event bg-green\" style=\"width: 200px;height: 35px;float: left;margin-left: 10px;margin-top: 10px;\" id=\""+result[i].bidSubscribeDetailId+"\" draggable=\"false\" onclick=\"getTime('"+result[i].bidSubscribeDetailId+"','"+result[i].subscribeStarttimeStr+"','"+result[i].subscribeEndtimeStr+"');\">"+result[i].subscribeStarttimeStr+" - "+result[i].subscribeEndtimeStr 
							+"<div style=\"position: relative;margin: 0 0 10  200;text-align: right;\">"+result[i].subCount+"/"+result[i].preSubCount+"</div>"
					 }
					 TimeList.innerHTML +=htmlStr;
				 }
				 var strElemt = "<div class=\"box-footer text-center\" style=\"margin-top: 320px;\" >"
                 +"<button type=\"button\" id=\"defaultProjId\" onclick=\"save();\" class=\"btn btn-success btn-sm\">预&nbsp;约</button>"
                 if(null != defaultProjId){
                	 strElemt += " <button type=\"button\" onclick=\"look();\" class=\"btn btn-default btn-sm\">查&nbsp;看</button></div>";
                 }else{
                	 strElemt += " <button type=\"button\" onclick=\"back();\" class=\"btn btn-default btn-sm\">返&nbsp;回</button></div>"; 
                 }
				 TimeList.innerHTML  += strElemt;
				}else{
					$.alert(result.msg || '操作失败！','信息', 'error');
				}
			}
		});
  } 
    </script>
  </body>
</html>
